const { join } = require('path');
const { src, dest, parallel } = require('gulp');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
const babel = require('gulp-babel');
const { paths } = require('./utils');

function concatJs() {
  return src(join(paths.dev.js, 'lib', '*.js'))
    .pipe(concat('vendor.js'))
    .pipe(uglify())
    .pipe(rename({ suffix: '.min' }))
    .pipe(dest(paths.prod.js));
}

function babelJs() {
  return src(join(paths.dev.js, '*.js'))
    .pipe(
      babel({
        presets: ['@babel/env'],
      })
    )
    .pipe(uglify())
    .pipe(rename({ suffix: '.min' }))
    .pipe(dest(paths.prod.js));
}

exports.js = parallel(concatJs, babelJs);
